<?php
namespace App\Services;
use Illuminate\Support\Facades\Cache;

class CodeService{
    public function send($phone,$templateCode){
        $code = $this->code($phone);
        if(app()->environment('local')) return $code;
        app(AliYunService::class)->sms($phone,$templateCode,['code'=>$this->code($phone)]);
        return $code;
    }
    protected function code($phone){
        //先判断缓存是否存在该手机的验证码
        if(Cache::get($phone)) abort(403,'请稍后再试');
        //Cache::put($phone,$code = mt_rand(100000,999999),config('my.code.out_time'));
        Cache::put($phone,$code = 952700,config('my.code.out_time'));
        return $code;
    }
}
